package com.lincoln.service;

import com.lincoln.entity.BaseEntity;
import com.lincoln.repository.BaseDao;

import java.util.Date;

/**
 * Service的一些基本方法
 *
 * @author lincoln
 * @param <ENTITY>
 * @param <REPOSITORY>
 */
public abstract class BaseService<ENTITY extends BaseEntity, REPOSITORY extends BaseDao<ENTITY>> extends BaseIdService<ENTITY, REPOSITORY> {
    /**
     * 保存实体类
     *
     * @param entity
     * @return
     */
    @Override
    public ENTITY save(ENTITY entity) {
        if (null == entity.getCreateTime()) {
            entity.setCreateTime(new Date());
            entity.setUpdateTime(new Date());
        } else {
            entity.setUpdateTime(new Date());
        }
        return repository.save(entity);
    }
}
